<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="zh-CN">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div1{
            width: 300px;
            height: 300px;
            background: red;
        }
        .show{
           display: block;
        }
        /* 隐藏 */
        .hidden{
            display: none;
        }
    </style>
    <script>
        window.onload = function(){
            var btnObj = document.getElementById("btn");
            var div1Obj = document.getElementById("div1");
            btnObj.onclick = function(){
                if(div1Obj.className == "show"){
                    div1Obj.className = "hidden";
                }else{
                    div1Obj.className = "show";
                }
            }
        }
    </script>
</head>
<body>
    <button id="btn" >点击我显示与隐藏div</button>
    <div class="show" id="div1"></div>
</body>
</html>